package com.hushui.mall.order.listener;


import com.hushui.mall.order.entity.OrderEntity;
import com.hushui.mall.order.service.OrderService;
import com.hushui.mall.order.to.OrderTo;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.nio.file.WatchService;

/**
 * @Author: hwh
 * @Date: 2023/03/18/15:24
 */
@Service
public class OrderCloseListener {
    @Autowired
    OrderService orderService;
    @RabbitListener(queues = "order.release.order.queue")
    public void handlerStockLockedRelease(OrderEntity order, Message message, Channel channel) throws IOException {
        System.out.println("收到的消息，准备关闭订单" + order.getOrderSn());
        try {
            orderService.closeOrder(order);
            channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
        } catch (Exception e) {
            channel.basicReject(message.getMessageProperties().getDeliveryTag(), true);
        }
    }

}
